package com.gs.zhss.eshop.auth.controller;

import com.gs.zhss.eshop.auth.domain.PriorityDTO;
import com.gs.zhss.eshop.auth.domain.PriorityVO;
import com.gs.zhss.eshop.auth.service.PriorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: gs
 * @Date: 2023/12/24 15:38
 * @Version: v1.0.0
 * @Description: TODO 权限管理模块的controller组件
 **/

@RestController
@RequestMapping("/auth")
public class PriorityController {

    @Autowired
    private PriorityService priorityService;

    /**
     * 查询根权限
     * @return 根权限集合
     */
    @GetMapping("/priority/root")
    public List<PriorityVO> listRootPriorities() {
        List<PriorityDTO> priorityDTOs = priorityService.listRootPriorities();

        List<PriorityVO> priorityVOs = new ArrayList<PriorityVO>(priorityDTOs.size());
        for(PriorityDTO priorityDTO : priorityDTOs) {
            priorityVOs.add(priorityDTO.clone(PriorityVO.class));
        }

        return priorityVOs;
    }
}
